<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
	<!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
	xmlns:uForum="urn:uForum"
	xmlns:uForum.raw="urn:uForum.raw"
	exclude-result-prefixes="uForum uForum.raw msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


	<xsl:output method="html" omit-xml-declaration="yes"/>

	<xsl:param name="currentPage"/>

	<xsl:template match="/">

		<xsl:if test="number($currentPage/forumAllowNewTopics) = 1 or number($currentPage/data [@alias='forumAllowNewTopics']) = 1">

			<xsl:variable name="p">
				<xsl:choose>
					<xsl:when test="string(number( umbraco.library:RequestQueryString('p') )) != 'NaN'">
						<xsl:value-of select="umbraco.library:RequestQueryString('p')"/>
					</xsl:when>
					<xsl:otherwise>0</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>

			<xsl:variable name="items">15</xsl:variable>
			<xsl:variable name="pages" select="uForum:ForumPager($currentPage/@id, $items, $p)"/>

			<xsl:variable name="topics" select="uForum.raw:Topics($currentPage/@id, $items, $p)//topic"/>

      <xsl:choose>
        <xsl:when test="uForum:CanPost()">
          <div class="infoBox" id="newTopic">
            <a href="{uForum:NicePostingUrl($currentPage/@id)}">Create a new topic</a>
            <br/>
            <small>Create a new topic in this forum</small>
          </div>
        </xsl:when>
        <xsl:otherwise>
          <div class="infoBox" id="newTopic">
            <span>You cannot post</span>
            <br/>
            <small>You do not have permission to post in this forum</small>
          </div>
        </xsl:otherwise>
      </xsl:choose>

			<xsl:if test="count($topics) &gt; 0">
				<table class="forumList" cellspacing="0">
					<thead>
						<tr>
							<th>Topic</th>
							<th class="replies">Replies</th>
							<th>Last post</th>
						</tr>
					</thead>
					<tbody>

						<xsl:for-each select="$topics">
							<xsl:sort select="updated" order="descending" />


							<xsl:call-template name="topic">
								<xsl:with-param name="topic" select="." />
							</xsl:call-template>



						</xsl:for-each>
					</tbody>
				</table>

				<xsl:if test="count($pages//page) &gt; 1">
					<strong>Pages: </strong>
					<ul class="pager">
						<xsl:for-each select="$pages//page">
							<li>
								<xsl:if test="@current = 'true'">
									<xsl:attribute name="class">current</xsl:attribute>
								</xsl:if>
								<a href="?p={@index}">
									<xsl:value-of select="@index + 1"/>
								</a>
							</li>
						</xsl:for-each>
					</ul>
				</xsl:if>

			</xsl:if>

		</xsl:if>
	</xsl:template>

	<xsl:template name="topic">
		<xsl:param name="topic"/>

		<tr id="topic{$topic/id}">
			<xsl:if test="$topic/answer != 0">
				<xsl:attribute name="class">solved</xsl:attribute>
			</xsl:if>

			<th class="title">

				<a href="{uForum:NiceTopicUrl($topic/id)}">
					<xsl:value-of select="$topic/title"/>
				</a>
				<small>
					Started by:  <xsl:value-of select="uForum:GetUserName($topic/memberId)"/>
					- <xsl:value-of select="uForum:TimeDiff($topic/created)"/>
					<xsl:if test="$topic/answer != 0">
						<em>&nbsp; - Topic has been solved</em>
					</xsl:if>
				</small>
			</th>

			<td class="replies">
				<xsl:value-of select="$topic/replies"/>
			</td>
			<td class="latestComment">
				<a href="{uForum:NiceTopicUrl($topic/id)}">
					<xsl:value-of select="uForum:TimeDiff($topic/updated)"/>
				</a> by

				<xsl:choose>
					<xsl:when test="number($topic/latestReplyAuthor) &gt; 0">
						<xsl:value-of select="uForum:GetUserName($topic/latestReplyAuthor)"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="uForum:GetUserName($topic/memberId)"/>
					</xsl:otherwise>
				</xsl:choose>
			</td>
		</tr>

	</xsl:template>



</xsl:stylesheet>